﻿<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>跨域通信实例</title>
	<script type="text/javascript">
	 //监听Message事件
	 window.addEventListener("message",function(ev){
	    //忽略指定URL地址之外的页面传来的消息
		if(ev.origin!="http://localhost:8089"){
		    return;
		}
		//显示消息
		alert("从"+ev.origin+"那里传过来的消息:\n\""+ev.data+"\"");
	 },false);
	 //say hello
	function hello(){
	 var iframe=window.frames[0];
	 //传递消息
	 iframe.postMessage("你好","http://localhost:8089/test/windowMessage.html");
	} 
	</script>
  </head>
  <body>
    <h1>跨域通信实例</h1>
	<iframe width="400" src="http://localhost:8089/test/iframePage.html" onload="hello()">
  </body>
</html>